/*
 *******************************************************************************
 * All rights Reserved, Copyright (C) www.gm-sz.com 2014
 * FileName: this.java
 * Modify record:
 * NO. |     Date       |    Version      |    Name           |      Content
 * 1   | 2014年4月22日        |   $Revision$  |  GMSZ)LuHaosheng  | original version
 *******************************************************************************
 */
package org.eae.eldf.webapp.common.bean;


/**
 * Class name:this
 * Description: 分页Bean
 */
public class Pagination {
	/** * 查询从第几个开始 */
	private int start = 0;
	/** * 结束index */
	private int end = 0;
	/** * 每页多少个 */
	private int count = 20;
	/** * 总共多少页 */
	private int pages = 0;
	/** * 当前第几页 */
	private int currentPage = 1;
	private int totalItems = 0;
	
	public int getStart() {
		return this.start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPages() {
		return pages;
	}
	public void setPages(int pages) {
		this.pages = pages;
	}
	public int getTotalItems() {
		return totalItems;
	}
	public void setTotalItems(int totalItems) {
		this.totalItems = totalItems;
	}
	
	public void setEnd(int end) {
		this.end = end;
	}
	public int getEnd() {
		return end;
	}
	
	public  void initPages(int totalCount) {
		int pages = 0;
		if (totalCount > 0) {
			if (totalCount % this.getCount() == 0) 
				pages = (int)(totalCount / this.getCount());
			else
				pages = (int)(totalCount / this.getCount()) + 1;
		}
		
		this.setTotalItems(totalCount);
		int end = 0;
		if(this.getCount()*this.getCurrentPage() >this.getTotalItems()){
			end = this.getTotalItems();
		}else{
			end = this.getCount()*this.getCurrentPage();}
		
		this.setPages(pages);
		this.setStart(this.getCount()*(this.getCurrentPage()-1));
		this.setEnd(end);
	}
}
